package com.markedquilt.Interview;
/*
 * PackageName: com.markedquilt.Interview
 * ClassName:   Num1716
 * Author:   zhang
 * Date:     Created in 2020/10/20
 * Description:
 * History:
 * <author>        <time>             <version>          <desc>
 * 作者姓名         修改时间            版本号              描述
 * zhang           2020/10/20      1.0
 */

/**
 * Title:
 * Project: LeetcodeProblem
 *
 * @author ZhangKe
 * Created on 2020/10/20
 */
public class num1716 {

    /**
     * 2,1,4,5,3,1,1,3
     * 1,2,3,1
     * @return 12 4
     * max(n) = max(n-1),max(n-2)+nums[n]
     * max(2) = max(nums[0],nums[1])
     * max(3) = max(nums[0],nums[1]),nums[0]+nums[2]-->max(2),nums[0]+nums[2]
     * max(4) = max(max(3),max(2)+nums[3])
     */
    public static int massage(int[] nums) {

        if (nums.length==0)
            return 0;
        else if (nums.length==1)
            return nums[0];
        else{
            int n=nums[0];        //n=2
            int p = Math.max(nums[0],nums[1]);    //p=6
            for (int i = 2; i < nums.length; i++) {   //5
                int reult = Math.max(n+nums[i],p);
                n = p;
                p = reult;
            }
            return p;
        }
    }

    /**
     * 提交时删除
     */
    public static void main(String[] args) {
        int[] array = new int[]{1,2,3,1};
        System.out.println(massage(array));
    }
}
